<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use think\Db;
use think\Request;
use think\Session;
class MyController extends HomeBaseController
{
    function my(){
        //dump(Session::get());
        $name = Db::name("users")->where("id",Session::get("uid"))->field("nickname")->find();
        $this->assign('photo',Session::get("photo"));
      /*  $this->assign('tt',Session::get("tt"));
        $this->assign('cc',Session::get("cc"));*/
        $this->assign('nickname',$name["nickname"]);
        $this->assign('uid',Session::get("uid"));
       return $this->fetch(':my');
    }
    function yuyue(){
        $data = Db::name('teacher_subscribe')
            ->join('qq_teacher', 'qq_teacher.id=qq_teacher_subscribe.teacher_id')
            ->where('qq_teacher_subscribe.user_id',Session::get("uid"))
            ->select();
        if(!isset($data[0])){
            $data="";
        }
//        dump($data).die;
       /* $undetermined_data = Db::name('teacher_subscribe')
            ->join('qq_teacher', 'qq_teacher.id=qq_teacher_subscribe.teacher_id')
            ->where('qq_teacher_subscribe.user_id',Session::get("uid"))
            ->where('qq_teacher_subscribe.static',0)
            ->select();
        if(!isset($undetermined_data[0])){
            $undetermined_data="";
        }
//        dump($undetermined_data).die;
        $accept_data = Db::name('teacher_subscribe')
            ->join('qq_teacher', 'qq_teacher.id=qq_teacher_subscribe.teacher_id')
            ->where('qq_teacher_subscribe.user_id',Session::get("uid"))
//            ->where('qq_teacher_subscribe.static',-1)
            ->where('qq_teacher_subscribe.static',1)
            ->select();
        if(!isset($accept_data[0])){
            $accept_data="";
        }
        $reject_data = Db::name('teacher_subscribe')
            ->join('qq_teacher', 'qq_teacher.id=qq_teacher_subscribe.teacher_id')
            ->where('qq_teacher_subscribe.user_id',Session::get("uid"))
            ->where('qq_teacher_subscribe.static',-1)
//            ->where('qq_teacher_subscribe.static',1)
            ->select();
        if(!isset($reject_data[0])){
            $reject_data="";
        }*/

//        dump($accept_data).die;
        $this->assign('data',$data);
       /* $this->assign('undetermined_data',$undetermined_data);
        $this->assign('reject_data',$reject_data);
        $this->assign('accept_data',$accept_data);*/
        return $this->fetch(":yuyue");
    }
    function shoucang(){
        $collect_data = Db::name('teacher_collect')
            ->join('qq_teacher', 'qq_teacher_collect.teacher_id=qq_teacher.id',"LEFT")
            ->where('qq_teacher_collect.user_id',Session::get("uid"))
            ->select();
        if(!isset($collect_data[0])){
            $collect_data="";
        }
        $this->assign('collect_data',$collect_data);
        return $this->fetch(":shoucang");
    }

    function comment(){
        if(input('subscribe_id')){
            /*dump(input('start'));
            die;*/
            $time = strtotime(date('Y-m-d'));
            $teacher_id = Db::name("teacher_subscribe")->where("id",input('subscribe_id'))->field("teacher_id")->find();
//            dump($teacher_id).die;
            $comment = ['subscribe_id'=>input('subscribe_id'),'comment_content'=>input('pingjia'),'start'=>input('start'),'commit_time'=>$time,'status'=>1,'user_id'=>Session::get("uid"),'teacher_id'=>$teacher_id["teacher_id"]];
//            dump($comment).die;
            $code = Db::name('teacher_comment')->insert($comment);
//            dump($code).die;
            if($code){
                Db::name('teacher_subscribe')->where('id',input('subscribe_id'))->update(['comment_static' => 1,]);
               return redirect(url('my/comment',array('content'=>input('pingjia'))));
            }
            else{
                $this->error('评价失败！！!');
            }

        }
        else{
            $time_cha =strtotime(date('Y-m-d'))-24;
            /* dump($time_cha);*/
            $map['qq_teacher_subscribe.commit_time']=['lt',$time_cha];
            $map['qq_teacher_subscribe.user_id']=['eq',Session::get("uid")];
            $map['qq_teacher_subscribe.static']=['eq',1];
            $map['qq_teacher_subscribe.comment_static']=['eq',0];
            $comment_data = Db::name('teacher')
                ->join('qq_teacher_subscribe', 'qq_teacher_subscribe.teacher_id=qq_teacher.id')
                ->where($map)
                ->select();
            /*dump($comment_data);
            die;*/
            $map1['qq_teacher_comment.status']=['eq',1];
            $map1['qq_teacher_comment.user_id']=['eq',Session::get("uid")];
            $accept_data = Db::name('teacher_comment')
                ->join('qq_teacher', 'qq_teacher_comment.teacher_id=qq_teacher.id',"LEFT")
                ->join('qq_teacher_subscribe', 'qq_teacher_comment.subscribe_id=qq_teacher_subscribe.id',"LEFT")
                ->where($map1)
                ->select();
            /*dump($accept_data);
            die;*/
            if(!isset($comment_data[0])){
                $comment_data="";
            }
            if(!isset($accept_data[0])){
                $accept_data="";
            }
           $this->assign('accept_data',$accept_data);
            $this->assign('comment_data',$comment_data);
            return $this->fetch(":comment_center");
        }

    }

/*    function update(){
        $id=input('id');
        $update_data=Db::name('teacher_subscribe')
            ->join('qq_teacher', 'teacher_subscribe.teacher_id=qq_teacher.id')
            ->where('id',$id)
            ->select();
        $this->assign('update_data',$update_data);
        return $this->fetch();

    }
    function pj(){
        $data=input();
        $id=$data['id'];
        $data['commit_time']=\Qiniu\time();
        $res=Db::name('teacher_subscribe')->where('id',$id)->update($data);
        if($res){
            //$this->success("评价成功",":comment");
            return $this->fetch(":comment");
        }
        else{
           // $this->error("评价失败",":pinglun");
            return $this->fetch(":pinglun");
        }
    }*/

    function pinglun(){
       $this->assign('subscribe_id',input('subscribe_id'));
        return $this->fetch(":pinglun");
    }

}
